package com.yueka.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yueka.pojo.entity.course.CourseStudent;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CourseStudentMapper extends BaseMapper<CourseStudent> {
    @Select("SELECT student_id FROM course_student WHERE course_id = #{id}")
    List<Integer> getStudentIds(Integer id);

    @Delete("DELETE FROM course_student WHERE course_id = #{id}")
    void deleteByCourseId(Integer id);

    void insert(Integer id, List<Integer> studentIds);

    @Insert("INSERT INTO course_student (course_id, student_id) VALUES (#{courseId}, #{studentId})")
    void subscribe(Integer studentId, Integer courseId);

    @Select("SELECT COUNT(*) FROM course_student WHERE course_id = #{courseId} AND student_id = #{studentId}")
    Integer isSubscribe(Integer studentId, Integer courseId);
}
